package com.zhongjian.technologycal.mall.activity.personal.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.zhongjian.technologycal.mall.R;
import com.zhongjian.technologycal.mall.base.BaseActivity;
import com.zhongjian.technologycal.mall.bean.FansAccountBean;
import com.zhongjian.technologycal.mall.net.HttpRetrofitClient;
import com.zhongjian.technologycal.mall.utils.NetWorkUtils;
import com.zhongjian.technologycal.mall.utils.StatusBarUtil;
import com.zhongjian.technologycal.mall.utils.ToastUitl;
import com.zhongjian.technologycal.mall.utils.UserUtils;

import butterknife.BindView;
import butterknife.OnClick;
import okhttp3.ResponseBody;
import rx.Subscriber;

/**
 * Created by wei on 2017/12/25.
 * 粉丝数量实现
 */

public class FansAccountActivity extends BaseActivity {
    @BindView(R.id.tv_main_title)
    TextView tv_main_title;
    @BindView(R.id.fans_ll_red)
    LinearLayout fans_ll_red;
    @BindView(R.id.fans_ll_blue)
    LinearLayout fans_ll_blue;
    @BindView(R.id.fans_ll_yellow)
    LinearLayout fans_ll_yellow;
    @BindView(R.id.fans_tv_red)
    TextView fans_tv_red;
    @BindView(R.id.fans_tv_blue)
    TextView fans_tv_blue;
    @BindView(R.id.fans_tv_yellow)
    TextView fans_tv_yellow;

    @Override
    protected void beforeInit() {
        super.beforeInit();
//        StatusBarUtil.setColorNoTranslucent(this, getResources().getColor(R.color.border_color));
//        StatusBarUtil.setMiuiStatusBarDarkMode(this, true);
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        tv_main_title.setText("我的粉丝");

    }

    @Override
    public void initPresenter() {
        initViewRequest();

    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_fans_accunt;
    }

    @OnClick(R.id.iv_back_page)
    public void onClickBack() {
        finish();
    }

    @OnClick(R.id.fans_ll_red)
    public void onClickRedFans() {
        Intent intent = new Intent();
        intent.setClass(getBaseContext(), CheckFansListActivity.class);
        intent.putExtra("tabstate", 0);
        startActivity(intent);

    }

    @OnClick(R.id.fans_ll_blue)
    public void onClickBlueFans() {
        Intent intent = new Intent();
        intent.setClass(getBaseContext(), CheckFansListActivity.class);
        intent.putExtra("tabstate", 1);
        startActivity(intent);

    }

    @OnClick(R.id.fans_ll_yellow)
    public void onClickYellowFans() {
        Intent intent = new Intent();
        intent.setClass(getBaseContext(), CheckFansListActivity.class);
        intent.putExtra("tabstate", 2);
        startActivity(intent);
    }


    private void initViewRequest() {
        if (!NetWorkUtils.isNetConnected(getBaseContext())) {
            ToastUitl.showShort(R.string.no_net);
            return;
        }
        HttpRetrofitClient.getInstance(getBaseContext())
                .getUrlRequestgetFans(UserUtils.getUserToken(),
                        new Subscriber<ResponseBody>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {

                            }

                            @Override
                            public void onNext(ResponseBody responseBody) {
                                try {
                                    Gson gson = new Gson();
                                    FansAccountBean fansAccountBean = gson.fromJson(responseBody.string(), FansAccountBean.class);
                                    if (fansAccountBean.getError_code() == 0) {
                                        fans_tv_red.setText("" + fansAccountBean.getData().getRed());
                                        fans_tv_blue.setText("" + fansAccountBean.getData().getBlue());
                                        fans_tv_yellow.setText("" + fansAccountBean.getData().getYellow());
                                    } else if (fansAccountBean.getError_code() == 3) {
                                        Intent intent = new Intent();
                                        intent.setAction("com.broadcast.info_out_line");
                                        sendBroadcast(intent);
                                    } else {
                                        ToastUitl.showShort(fansAccountBean.getError_message());
                                    }

                                } catch (Exception e) {
                                    e.printStackTrace();
                                }


                            }
                        });


    }

}
